package extrace.ui.main.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import extrace.loader.LoginLoader;
import extrace.net.HttpAsyncTask;
import extrace.ui.main.R;


public class LoginActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
        setContentView(R.layout.login);

        getWindow().setStatusBarColor(Color.TRANSPARENT);
        ImageButton btngoback = findViewById(R.id.ibtn_back);
        btngoback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginActivity.this.finish();
            }
        });
        final EditText account = findViewById(R.id.et_QQ);
        final EditText passwd = findViewById(R.id.et_password);
        Button button = findViewById(R.id.btn_login);
        final LoginLoader loginLoader = new LoginLoader(this);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (account.getText().toString().matches("[a-zA-Z0-9]{2,30}") && passwd.getText().toString().matches("[a-zA-Z0-9]{2,30}")) {
                    loginLoader.doLogin(Integer.parseInt(account.getText().toString()), passwd.getText().toString());
                } else {
                    Toast.makeText(getApplicationContext(), "请输入正确的账户密码", Toast.LENGTH_SHORT).show();
                }
            }

        });
    }
}


